#include "json.h"

/** streams a binary stream to JSON */
int main(void)
	{
	int c;
	JSONNodePtr root=NULL;
	
	//create a new array of bytes
	DataStream arrayOfBytes =DataStreamNew();
	if(arrayOfBytes==NULL)
		{
		return EXIT_FAILURE;
		}
		
	//fill the array of bytes
	while((c=fgetc(stdin))!=EOF)
		{
		if(DataStreamAppendC(arrayOfBytes,c)!=1)
			{
			DataStreamFree(arrayOfBytes);
			return EXIT_FAILURE;
			}
		}
	//unserialize the data
	root = JSONDeserialize(arrayOfBytes);
	if(root==NULL)
		{
		DataStreamFree(arrayOfBytes);
		return EXIT_FAILURE;
		}
	//print the JSON tree
	JSONPrint(stdout,root);
	DataStreamFree(arrayOfBytes);
	JSONNodeFree(root);
	return EXIT_SUCCESS;
	}